package idv.cjcat.pyronova.nodes {
	import flash.geom.Matrix;
	import flash.geom.Point;
	import idv.cjcat.pyronova.render.RenderVisitor;
	import idv.cjcat.pyronova.utils.GraphicsUtils;
	
	public class LineSegments extends Node {
		
		public var points:Vector.<Number>;
		public var colors:Vector.<uint>;
		public var useAlpha:Boolean;
		
		public function LineSegments(points:Vector.<Number> = null, colors:Vector.<uint> = null, useAlpha:Boolean = true) {
			this.points = points;
			this.colors = colors;
			this.useAlpha = useAlpha;
		}
		
		private var p:Point = new Point();
		private var transformedPoints:Vector.<int> = new Vector.<int>();
		override public function render(visitor:RenderVisitor):void {
			transformedPoints.length = points.length;
			var i:int = 0, len:int = points.length;
			while (i < len) {
				p.x = points[i];
				p.y = points[i + 1];
				p = visitor.topMatrix().transformPoint(p);
				transformedPoints[i++] = int(p.x + 0.5);
				transformedPoints[i++] = int(p.y + 0.5);
			}
			GraphicsUtils.drawLineSegments(transformedPoints, colors, useAlpha, visitor.graphics().topBuffer());
		}
	}
}